package com.ruoyi.project.naming.namingop.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.naming.namingop.domain.NamingOp;
import com.ruoyi.project.naming.namingop.service.INamingOpService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 起名上报Controller
 *
 * @author shixiangwen
 * @date 2022-04-21
 */
@Controller
@RequestMapping("/naming/namingop")
public class NamingOpController extends BaseController {
    private String prefix = "naming/namingop";

    @Autowired
    private INamingOpService namingOpService;

    @RequiresPermissions("naming:namingop:view")
    @GetMapping()
    public String namingop() {
        return prefix + "/namingop";
    }

    /**
     * 查询起名上报列表
     */
    @RequiresPermissions("naming:namingop:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(NamingOp namingOp) {
        startPage();
        List<NamingOp> list = namingOpService.selectNamingOpList(namingOp);
        return getDataTable(list);
    }

    /**
     * 导出起名上报列表
     */
    @RequiresPermissions("naming:namingop:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(NamingOp namingOp) {
        List<NamingOp> list = namingOpService.selectNamingOpList(namingOp);
        ExcelUtil<NamingOp> util = new ExcelUtil<NamingOp>(NamingOp.class);
        return util.exportExcel(list, "namingop");
    }

    /**
     * 新增起名上报
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存起名上报
     */
    @RequiresPermissions("naming:namingop:add")
    @Log(title = "起名上报", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(NamingOp namingOp) {
        return toAjax(namingOpService.insertNamingOp(namingOp));
    }

    /**
     * 修改起名上报
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        NamingOp namingOp = namingOpService.selectNamingOpById(id);
        mmap.put("namingOp", namingOp);
        return prefix + "/edit";
    }

    @RequiresPermissions("monitor:namingop:detail")
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") Long id, ModelMap mmap) {
        mmap.put("namingOp", namingOpService.selectNamingOpById(id));
        return prefix + "/detail";
    }


    /**
     * 修改保存起名上报
     */
    @RequiresPermissions("naming:namingop:edit")
    @Log(title = "起名上报", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(NamingOp namingOp) {
        return toAjax(namingOpService.updateNamingOp(namingOp));
    }

    /**
     * 删除起名上报
     */
    @RequiresPermissions("naming:namingop:remove")
    @Log(title = "起名上报", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(namingOpService.deleteNamingOpByIds(ids));
    }
}
